home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / util / blank / bserver_v14.lha / BServer_v1.4 / Sources.lha / Sources / server / modeid.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-23  |  3.4 KB  |  138 lines

  1. #include <exec/memory.h>
  2. #include <graphics/displayinfo.h>
  3. #include <graphics/modeid.h>
  4. #include <string.h>
  5.  
  6. #include <proto/exec.h>
  7. #include <proto/graphics.h>
  8. #include <clib/alib_protos.h>
  9.  
  10. #include "/include/server.h"
  11.  
  12. extern UBYTE briLevel;
  13.  
  14. struct List *ModeList;
  15. struct ModeNode *DisplayNode;
  16. ULONG DisplayID = PAL_MONITOR_ID;
  17.  
  18. char DefaultModeName[DISPLAYNAMELEN];
  19.  
  20.  
  21. void DeleteModeList( void )
  22. {
  23. struct ModeNode *ModeNode;
  24.  
  25. while (ModeList->lh_Head->ln_Succ)
  26.     {
  27.     ModeNode=(struct ModeNode *)ModeList->lh_Head;
  28.     RemHead (ModeList);
  29.     FreeVec( ModeNode );
  30.     }
  31. FreeVec( ModeList );
  32. }
  33.  
  34.  
  35. struct List *CreateModeList(void)
  36. {
  37. UWORD Index = 0;
  38. ULONG NewDisplID;
  39. struct DimensionInfo DimInfo;
  40. struct NameInfo NameInfo;
  41. struct ModeNode *NewNode;
  42.  
  43. if ( ModeList = AllocVec( sizeof(struct List), MEMF_PUBLIC ) )
  44.     NewList( ModeList );
  45. else
  46.     return( NULL );
  47.  
  48. NewDisplID=INVALID_ID;
  49.  
  50. while ( ( NewDisplID = NextDisplayInfo( NewDisplID ) ) != INVALID_ID )
  51.     if ( ( NewDisplID & MONITOR_ID_MASK ) && ( !ModeNotAvailable( NewDisplID ) ) )
  52.         if ( GetDisplayInfoData( NULL, (UBYTE *)&DimInfo, sizeof(struct DimensionInfo), DTAG_DIMS, NewDisplID ) )
  53.             if ( GetDisplayInfoData( NULL, (UBYTE *)&NameInfo, sizeof(struct NameInfo), DTAG_NAME, NewDisplID ) )
  54.                 if ( NewNode = AllocVec( sizeof(struct ModeNode), MEMF_CLEAR ) )
  55.                 {
  56.                 NewNode->mn_Node.ln_Name = NewNode->mn_Name;
  57.                 NewNode->mn_DisplayID = NewDisplID;
  58.                 NewNode->mn_Index = Index++;
  59.                 strcpy( NewNode->mn_Name, NameInfo.Name );
  60.                 AddTail( ModeList, (struct Node *)NewNode );
  61.                 }
  62.  
  63. if ( !ModeList->lh_Head->ln_Succ )
  64.     DisplayID = 0L;
  65.  
  66. if ( DisplayID == INVALID_ID )
  67.     {
  68.     if ( NewNode = (struct ModeNode *)FindName( ModeList, DefaultModeName ) )
  69.         DisplayID = NewNode->mn_DisplayID;
  70.     else
  71.         DisplayID = PAL_MONITOR_ID;
  72.     }
  73.  
  74. return( ModeList );
  75. }
  76.  
  77.  
  78. void GetDisplayNodeFromID( void )
  79. {
  80. if ( DisplayID != 0L )
  81.     {
  82.     DisplayNode = (struct ModeNode *)ModeList->lh_Head;
  83.  
  84.     while( DisplayNode && DisplayNode->mn_DisplayID != DisplayID )
  85.         DisplayNode = (struct ModeNode *)DisplayNode->mn_Node.ln_Succ;
  86.  
  87.     if ( !DisplayID || !DisplayNode )
  88.         {
  89.         DisplayNode = (struct ModeNode *)ModeList->lh_Head;
  90.         DisplayID = DisplayNode->mn_DisplayID;
  91.         }
  92.     }
  93. }
  94.  
  95.  
  96. void GetDisplayNodeFromName( void )
  97. {
  98. if ( ModeList->lh_Head->ln_Succ )
  99.     {
  100.     if ( (*DefaultModeName != 0) && (DisplayNode = (struct ModeNode *)FindName( ModeList, DefaultModeName )) )
  101.         DisplayID = DisplayNode->mn_DisplayID;
  102.     else
  103.         DisplayID = PAL_MONITOR_ID;
  104.     }
  105.     else
  106.         DisplayID = 0L;
  107. }
  108.  
  109.  
  110. void GetDisplayIDFromNode( UWORD Index )
  111. {
  112. DisplayNode = (struct ModeNode *)ModeList->lh_Head;
  113.  
  114. while( DisplayNode && DisplayNode->mn_Index != Index )
  115.     DisplayNode = (struct ModeNode *)DisplayNode->mn_Node.ln_Succ;
  116.  
  117. DisplayID = DisplayNode->mn_DisplayID;
  118. }
  119.  
  120.  
  121. struct DisplayIDInformation *AllocDisplayIDInformation( ULONG whichDisplayID )
  122. {
  123. struct DisplayIDInformation *diinfo;
  124.  
  125. if ( diinfo = AllocVec( sizeof(struct DisplayIDInformation), MEMF_PUBLIC ) )
  126.     {
  127.     if ( GetDisplayInfoData( NULL, (UBYTE *)&diinfo->di_DisplayInfo, sizeof(struct DisplayInfo), DTAG_DISP, whichDisplayID ) )
  128.         if ( GetDisplayInfoData( NULL, (UBYTE *)&diinfo->di_DimensionInfo, sizeof(struct DimensionInfo), DTAG_DIMS, whichDisplayID ) )
  129.                 if ( GetDisplayInfoData( NULL, (UBYTE *)&diinfo->di_MonitorInfo, sizeof(struct MonitorInfo), DTAG_MNTR, whichDisplayID ) )
  130.                     {
  131.                     diinfo->di_Brightness = briLevel;
  132.                     return( diinfo );
  133.                     }
  134.     FreeVec( diinfo );
  135.     }
  136. return( NULL );
  137. }
  138.